package com.ruoyi.memo.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.memo.domain.MemoSchedule;
import com.ruoyi.memo.service.IMemoScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日程Controller
 * 
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/memo/schedule")
public class MemoScheduleController extends BaseController
{
    @Autowired
    private IMemoScheduleService memoScheduleService;

    @GetMapping(value = "/date/{date}")
    public AjaxResult getInfoByDate(@PathVariable("date") Date date)
    {
        return success(memoScheduleService.selectScheduleByUserIdAndDate(SecurityUtils.getUserId(),date));
    }

    @GetMapping("/userlist")
    public TableDataInfo userlist(MemoSchedule memoSchedule)
    {
        memoSchedule.setUserId(SecurityUtils.getUserId());
        startPage();
        List<MemoSchedule> list = memoScheduleService.selectMemoScheduleList(memoSchedule);
        return getDataTable(list);
    }
    /**
     * 查询日程列表
     */
    @PreAuthorize("@ss.hasPermi('memo:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemoSchedule memoSchedule)
    {
        startPage();
        List<MemoSchedule> list = memoScheduleService.selectMemoScheduleList(memoSchedule);
        return getDataTable(list);
    }

    /**
     * 导出日程列表
     */
    @PreAuthorize("@ss.hasPermi('memo:schedule:export')")
    @Log(title = "日程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemoSchedule memoSchedule)
    {
        List<MemoSchedule> list = memoScheduleService.selectMemoScheduleList(memoSchedule);
        ExcelUtil<MemoSchedule> util = new ExcelUtil<MemoSchedule>(MemoSchedule.class);
        util.exportExcel(response, list, "日程数据");
    }

    /**
     * 获取日程详细信息
     */
//    @PreAuthorize("@ss.hasPermi('memo:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memoScheduleService.selectMemoScheduleById(id));
    }

    /**
     * 新增日程
     */
//    @PreAuthorize("@ss.hasPermi('memo:schedule:add')")
    @Log(title = "日程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemoSchedule memoSchedule)
    {
        return toAjax(memoScheduleService.insertMemoSchedule(memoSchedule));
    }

    /**
     * 修改日程
     */
//    @PreAuthorize("@ss.hasPermi('memo:schedule:edit')")
    @Log(title = "日程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemoSchedule memoSchedule)
    {
        return toAjax(memoScheduleService.updateMemoSchedule(memoSchedule));
    }

    /**
     * 删除日程
     */
//    @PreAuthorize("@ss.hasPermi('memo:schedule:remove')")
    @Log(title = "日程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memoScheduleService.deleteMemoScheduleByIds(ids));
    }
}
